package com.hlkj.pay.util.excel;

import cn.hutool.core.date.DatePattern;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.hlkj.pay.util.DateUtils;

public class TimestampToDateConverter implements Converter<Long> {

    @Override
    public Class supportJavaTypeKey() {
        return Long.class;
    }

    @Override
    public com.alibaba.excel.enums.CellDataTypeEnum supportExcelTypeKey() {
        return com.alibaba.excel.enums.CellDataTypeEnum.STRING;
    }

    @Override
    public WriteCellData<?> convertToExcelData(WriteConverterContext<Long> context) {
        // 将 Java 数据写回到 Excel
        Long value = context.getValue();
        if (value == null) {
            return new WriteCellData<>("");
        }
        return new WriteCellData<>(DateUtils.dateToString(value, DatePattern.NORM_DATETIME_PATTERN));
    }
}